package com.community.backend.service.impl;

import cn.hutool.core.lang.UUID;
import cn.hutool.system.UserInfo;
import com.community.backend.mapper.PropertyMapper;
import com.community.backend.mapper.SecurityMapper;
import com.community.backend.pojo.Property;
import com.community.backend.pojo.Security;
import com.community.backend.pojo.dto.LoginDTO;
import com.community.backend.pojo.dto.PropertyQueryDTO;
import com.community.backend.pojo.dto.RegisterDTO;
import com.community.backend.pojo.vo.PropertyQueryVO;
import com.community.backend.service.PropertyService;
import com.community.backend.service.SecurityService;
import com.community.backend.utils.PageResult;
import com.community.backend.utils.Result;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PropertyServiceImpl implements PropertyService {
    @Autowired
    private PropertyMapper propertyMapper;
    @Override
    public PageResult propertyByPage(PropertyQueryDTO propertyQueryDTO) {
        PageHelper.startPage(propertyQueryDTO.getCurrentPage(),propertyQueryDTO.getPageSize());
        Page<PropertyQueryVO> page = propertyMapper.pageQuery(propertyQueryDTO);
        System.out.println("propertyByPage分页信息"+page);
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public void update(Property property) {
        Integer rows = propertyMapper.update(property);

    }

    @Override
    public void deleteById(String id) {
        Property property = new Property();
        property.setId(id);
        Integer rows = propertyMapper.updateById(property);

    }

    @Override
    public void addProperty(Property property) {
        property.setId(UUID.randomUUID().toString());
        property.setUsername(property.getName());
        property.setPassword("123456");
        property.setStatus("在职");
        property.setIsDelete("未删除");
        Integer rows = propertyMapper.add(property);

    }

    @Override
    public void register(RegisterDTO registerDTO) {
        propertyMapper.register(registerDTO);
    }

    @Override
    public Property login(LoginDTO loginDTO) {
        Property property = propertyMapper.login(loginDTO.getUsername(), loginDTO.getPassword());
        return property;
    }

}
